import pyautogui
import pydirectinput
import time
import keyboard
import pygetwindow
import random
import sys
import ctypes
import os
import fileinput
import subprocess
import ctypes
# 获取指定标题的程序窗口对象
program_window = pygetwindow.getWindowsWithTitle('星穹铁道')[0]
# 获取窗口左上角的位置
top_left_position = program_window.topleft
print(top_left_position)
x1 = top_left_position.x
y1 = top_left_position.y

def r():
    random_number = random.uniform(0.7, 0.9)
    time.sleep(random_number)
def rr():
    random_number = random.uniform(1.5, 2.0)
    time.sleep(random_number)
def rrr():
    time.sleep(15)
def sleep(t):
    time.sleep(t)
def click(x,y):
    pydirectinput.click(x+x1, y+y1)#点击
    r()
def press(m):
    pydirectinput.press(m)#按键
    r()


def te():
    time.sleep(2)
    click(400,400)
    rr()
    pydirectinput.keyDown("alt")
    click(211,243) #开局短信
    pydirectinput.keyUp("alt")

def fight(n,t):
    press("f")
    for i in range(n-1):
        click(1542,786) #增加次数
    click(1333,848) #挑战
    # 增援
    click(1433,646) #支援
    click(1391,852) #入队
    click(1391,852) #开始挑战

    #攻击出发挑战（升级材料需要）
    sleep(2)
    press("w")
    click(400,400) 
    
    print("t*n="+str(t)+"*"+str(n)+"="+str(t*n))
    #等待战斗
    sleep(t*n)

    click(581,818) #退出关卡
    sleep(5)

if __name__ == "__main__":
    sleep(3)
    
    pyautogui.moveTo(x1+659,y1+500)
    r()
    for i in range(29):
        pyautogui.scroll(-100)
        # r()
    click(1283,760) #传送
    sleep(5) #等待传送

    # fight(1,120)


   

print("end")